<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" name="" id="title">
    <textarea name="" id="content" cols="30" rows="10"></textarea>
    <button onclick="publicArticleFn()">发布文章</button>
    <ul>
        <!-- <li>
            <h2></h2>
        </li> -->
    </ul>
    <!--  -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.5.0/axios.js"></script>
    <script src="./request.js"></script>
    <script>
        let articleAPI = '/articles';

        async function publicArticleFn() {
            let title = document.querySelector("#title").value;
            let content = document.querySelector('#content').value;
            let r = await http.post(articleAPI, { title, content });
            console.log(r);
        }

        async function loadList() {
            let r = await http.get(articleAPI)
            console.log(r.data);
            let liStwr = r.data.data.map(v => `  <li>
            <h2>${v.title}</h2>
        </li>`);
            document.querySelector('ul').innerHTML = liStwr
        }

        loadList()
    </script>

</body>

</html>